package com.huika.renrench.control.investment.adapter;

import java.util.HashMap;

import android.content.Context;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huika.lib.utils.MoneyShowTool;
import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAda;

public class InvestmentRecordAdapter extends BaseAda<HashMap<String, String>> {

	private SparseArray<View> map = new SparseArray<View>();
	
	public InvestmentRecordAdapter(Context context) {
		super(context);
	}

	private static class ViewHolder {
		TextView name;
		TextView money;
		TextView time;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null; 
		if(map.get(position) == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_invest_record, null);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.money = (TextView) convertView.findViewById(R.id.money);
			holder.time = (TextView) convertView.findViewById(R.id.time);
			convertView.setTag(holder);
			final int p = position;
			map.put(p, convertView);
		} else {
			convertView = map.get(position);
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.name.setText(getHideName(group.get(position).get("userName")));
		holder.money.setText(MoneyShowTool.twolastDF(Double.parseDouble(group.get(position).get("investAmount"))) + "元");
		holder.time.setText(group.get(position).get("createTime"));
		return convertView;
	}
	
	private String getHideName(String name) {
		if(!TextUtils.isEmpty(name)) {
			
			StringBuffer sb = new StringBuffer(name.substring(0, 1));
			int count = name.length() - 1;
			for(int i = 0; i < count; i++) {
				sb.append('*');
			}
			return sb.toString();
		}
		return "  ";
	}

}
